import axios from "axios";
import store from "./store/store.js";
import utils from "@/utils/utils";

const request = axios.create();

const ip = process.env.VUE_APP_API_IP;

const dazhongIp_windows = "http://192.168.1.93:8083";

request.withCredentials = true;
request.interceptors.request.use(
  config => {
    const token = store.getters.token;
    config.headers.common["Authorization"] = token;
    return config;
  },
  error => {
    return Promise.reject(error);
  }
);

// 响应拦截器
// request.interceptors.response.use(
//   response => {
//    // 在这里做响应的批量错误处理和数据库拦截
//     return response
//   },
//   err => {
//     console.log(err)
//     // store.dispatch("logout").then(() => {
//     //   window.location.reload();
//     // });
//   }
// )

export const auth = params => {
  return request.post(`${ip}/user/login`, params).then(res => res.data);
};

export const getUserInfo = params => {
  return request.get(`${ip}/user/me`, params).then(res => res.data);
};

// 获取城市列表
export const getCityList = params => {
  return request
    .get(`${ip}/city/search`, {
      params
    })
    .then(res => res.data);
};

// 编辑城市
export const editCity = params => {
  return request.put(`${ip}/city`, params).then(res => res.data);
};

// 新增城市
export const addCity = params => {
  return request.post(`${ip}/city`, params).then(res => res.data);
};
// 移除城市
export const removeCity = id => {
  return request.delete(`${ip}/city/` + id).then(res => res.data);
};

// 获取全部城市列表及城市下企业列表
export const getCompanyListAll = params => {
  return request
    .get(`${ip}/company/groups`, {
      params
    })
    .then(res => res.data);
};

// 获取企业列表
export const getCompanyList = params => {
  return request
    .get(`${ip}/company`, {
      params
    })
    .then(res => res.data);
};

// 新增企业
export const addCompany = params => {
  return request.post(`${ip}/company`, params).then(res => res.data);
};

// 编辑企业
export const editCompany = params => {
  return request.put(`${ip}/company`, params).then(res => res.data);
};

// 根据企业id获取企业信息
export const getCompanyDetailByCompanyId = id =>
  request.get(`${ip}/company/${id}`).then(res => res.data);

// 根据用户id获取企业信息
export const getCompanyDetailByUserId = params =>
  request
    .get(`${ip}/user/getCompany`, {
      params
    })
    .then(res => res.data);

// 删除企业
export const removeCompany = id => {
  return request.delete(`${ip}/company/` + id).then(res => res.data);
};

// 通过城市筛选企业
export const getCompanyListByCity = params => {
  return request
    .get(`${ip}/company/search`, {
      params
    })
    .then(res => res.data);
};

// 通过企业筛选设备 设备： 参数：companyId（企业主键ID）
export const getDeviceListByCompany = params => {
  return request
    .get(`${ip}/device/search`, {
      params
    })
    .then(res => res.data);
};

// 用户列表
export const getUsersList = params => {
  return request
    .get(`${ip}/user/list`, {
      params
    })
    .then(res => res.data);
};

// 获取企业列表组
export const getGroupList = params => {
  return request
    .get(`${ip}/device/group`, {
      params
    })
    .then(res => res.data);
};

// 编辑企业组
export const editGroup = params => {
  return request.put(`${ip}/device/group`, params).then(res => res.data);
};

// 新增企业组
export const addGroup = params => {
  return request.post(`${ip}/device/group`, params).then(res => res.data);
};

// 编辑用户信息
export const editUser = params => {
  return request.put(`${ip}/user`, params).then(res => res.data);
};

// 修改用户密码
export const chagePwd = params => {
  return request.post(`${ip}/user/pwd`, params).then(res => res.data);
};
// 新增用户
export const addUser = params => {
  return request.post(`${ip}/user`, params).then(res => res.data);
};

export const removeGroup = id => {
  return request.delete(`${ip}/device/group/` + id).then(res => res.data);
};

// 移除用户
export const removeUser = id => {
  return request.delete(`${ip}/user/` + id).then(res => res.data);
};

// 踢出用户
export const kickUser = params => {
  return request
    .get(`${ip}/app/kick`, {
      params: params
    })
    .then(res => res.data);
};

// 获取用户组
export const getUserGroupList = params => {
  return request
    .get(`${ip}/role`, {
      params
    })
    .then(res => res.data);
};

// 获取事件日志列表
export const getServiceLogList = params => {
  return request
    .get(`${ip}/servicelog`, {
      params: params
    })
    .then(res => res.data);
};

export const addServiceLog = params => {
  return request.post(`${ip}/servicelog`, params).then(res => res.data);
};

// 获取设备日志列表
export const getDeviceLogList = params => {
  return request
    .get(`${ip}/app/statusLog`, {
      params
    })
    .then(res => res.data);
};

// 获取设备列表
export const getDevicesList = params => {
  return request
    .get(`${ip}/device`, {
      params
    })
    .then(res => res.data);
};

// 获取设备详情列表
export const getRealtimeDataList = params => {
  return request
    .get(`${ip}/device/realtime-datas`, {
      params
    })
    .then(res => res.data);
};

// 启动停止设备
export const startDevice = params => {
  return request.post(`${ip}/device/start`, params).then(res => res.data);
};
export const addDevice = params => {
  return request.post(`${ip}/device`, params).then(res => res.data);
};
export const stopDevice = params => {
  return request.post(`${ip}/device/stop`, params).then(res => res.data);
};

export const editDevice = params => {
  return request.put(`${ip}/device`, params).then(res => res.data);
};

export const removeDevice = id => {
  return request.delete(`${ip}/device/` + id).then(res => res.data);
};

// 获取设备参数
export const getDeviceAliasList = params => {
  return request
    .get(`${ip}/channel/settings`, {
      params
    })
    .then(res => res.data);
};

// 变量列表
export const getDeviceParamList = params => {
  return request
    .get(`${ip}/device/params/list`, {
      params
    })
    .then(res => res.data);
};

// 获取电流列表
export const getCurDataList = params => {
  return request
    .get(`${ip}/device/cur-datas`, {
      params
    })
    .then(res => res.data);
};

// 获取电压列表
export const getVolDataList = params => {
  return request
    .get(`${ip}/device/vol-datas`, {
      params
    })
    .then(res => res.data);
};

// 获取报警事件列表
export const getAlarmEventList = params => {
  return request
    .get(`${ip}/exceptions`, {
      params
    })
    .then(res => res.data);
};

// 历史数据列表
export const getHistoryList = params => {
  return request
    .get(`${ip}/device/datas`, {
      params
    })
    .then(res => res.data);
};

export const getCityListOfAll = params => {
  return request
    .get(`${ip}/city`, {
      params
    })
    .then(res => res.data);
};

export const getTopList = params => {
  return request
    .get(`${ip}/report/safe`, {
      params
    })
    .then(res => res.data);
};

export const getBottomList = params => {
  return request
    .get(`${ip}/report/power`, {
      params
    })
    .then(res => res.data);
};

// 诊断报告 中性线
export const getneutralLineList = params => {
  return request
    .get(`${ip}/report/detail-lx`, {
      params
    })
    .then(res => res.data);
};

// 电流 / 温度
export const getCurrentWithTem = params => {
  return request
    .get(`${ip}/report/detail-ct`, {
      params
    })
    .then(res => res.data);
};

// 谐波
export const getHarmonicList = params => {
  return request
    .get(`${ip}/report/detail-xb`, {
      params
    })
    .then(res => res.data);
};

/**
 *  新接口
 */

// 城市列表
export const getCityListOfNew = params => {
  return request
    .get(`${ip}/city/search`, {
      params
    })
    .then(res => res.data);
};
// 获取企业列表
export const getCompanyListOfNew = params => {
  return request
    .get(`${ip}/company/query`, {
      params
    })
    .then(res => res.data);
};

// 获取设备列表
export const getDeviceListOfNew = params => {
  return request
    .get(`${ip}/device/query`, {
      params
    })
    .then(res => res.data);
};

// 单条件企业列表
export const getCompanyListOfSingle = params => {
  return request
    .get(`${ip}/company/search`, {
      params
    })
    .then(res => res.data);
};

// 新增用户

export const getUserListOfNew = params => {
  return request
    .get(`${ip}/user/companyuser`, {
      params
    })
    .then(res => res.data);
};

// 新增通知
export const addNewAlarm = params => {
  return request.post(`${ip}/exceptions/inform`, params).then(res => res.data);
};

// 获取通知记录
export const getAlarmNoticeList = params => {
  return request
    .get(`${ip}/exceptions/inform`, {
      params
    })
    .then(res => res.data);
};

// 文章管理
export const addArtical = params => {
  return request.post(`${ip}/news`, params).then(res => res.data);
};

export const editArtical = params => {
  return request.put(`${ip}/news`, params).then(res => res.data);
};

export const deleteArtical = id => {
  return request.delete(`${ip}/news/` + id).then(res => res.data);
};

export const getArical = params => {
  return request
    .get(`${ip}/news`, {
      params
    })
    .then(res => res.data);
};
export const uploadImage = params => {
  return request.post(`${ip}/news/upload`, params).then(res => res.data);
};

// 获取历史数据曲线列表

export const getChartDataList = params => {
  return request
    .get(`${ip}/device/chart-data`, {
      params
    })
    .then(res => res.data);
};

// 代理商引导页, 获取代理商列表 getCompanyListByCity rname = "ROLE_PLATFORM" 代理商 首页接口
// http://192.168.1.90:8081/index

export const getInfoOfIndex = params => {
  return request
    .get(`${ip}/index`, {
      params
    })
    .then(res => res.data);
};

// 首页获取异常事件接口
export const getIndexException = params => {
  return request
    .get(`${ip}/index/exception`, {
      params
    })
    .then(res => res.data);
};

//
export const getIndexDlInfo = params => {
  return request
    .get(`${ip}/index/dl`, {
      params
    })
    .then(res => res.data);
};

export const getDeviceList = params => {
  return request
    .get(`${ip}/index/cd`, {
      params
    })
    .then(res => res.data);
};
export const getGroupByDevice = params =>
  request({
    url: `${ip}/device/findGroupByDeviceId`,
    method: "get",
    params
  }).then(res => res.data);

// 设备处理
export const editState = id => {
  return request
    .put(`${ip}/exceptions/disposed?id=` + id)
    .then(res => res.data);
};

// 设备消声
export const processSilent = id => {
  return request.put(`${ip}/exceptions/silent?id=` + id).then(res => res.data);
};

export const getDeviceDetail = id => {
  return request.get(`${ip}/device/${id}`).then(res => res.data);
};

// 设备停止启动
export const processOff = id => {
  return request.put(`${ip}/device/off?id=` + id).then(res => res.data);
};
export const processOn = id => {
  return request.put(`${ip}/device/on?id=` + id).then(res => res.data);
};

export const getDianliangDataList = params => {
  return request
    .get(`${ip}/device/dianliang-datas`, {
      params
    })
    .then(res => res.data);
};

export const getFuheDataList = params => {
  return request
    .get(`${ip}/device/fuhe-datas`, {
      params
    })
    .then(res => res.data);
};

export const getEnergyDataList = params => {
  return request
    .get(`${ip}/device/energy-datas`, {
      params
    })
    .then(res => res.data);
};

export const getFuhe = params =>
  request
    .get(`${ip}/nx/fh`, {
      params
    })
    .then(res => res.data);

export const getYinShu = params => {
  return request
    .get(`${ip}/nx/ys`, {
      params
    })
    .then(res => res.data);
};

export const getPowerDay = params => {
  return request
    .get(`${ip}/nx/month-power`, {
      params
    })
    .then(res => res.data);
};

// user/设备管理/能效阈值

export const getThreshold = params => {
  return request
    .get(`${ip}/device/threshold`, {
      params
    })
    .then(res => res.data);
};

export const updateThreshold = params => {
  return request.post(`${ip}/device/threshold`, params).then(res => res.data);
};

export const getInterval = params => {
  return request
    .get(`${ip}/setInterval`, {
      params
    })
    .then(res => res.data);
};

export const setInterval_ = params => {
  return request.post(`${ip}/setInterval`, params).then(res => res.data);
};

export const getcollectorParams = id => {
  return request.get(`${ip}/collector/params/${id}`).then(res => res.data);
};

export const setcollectorParams = params => {
  return request.put(`${ip}/collector/params`, params).then(res => res.data);
};

export const savecollectorParams = params => {
  return request.post(`${ip}/collector/params`, params).then(res => res.data);
};

export const getAlarmSettingList = params => {
  return request
    .get(`${ip}/device/params/query`, {
      params
    })
    .then(res => res.data);
};

export const setAlarmSettingList = params => {
  return request
    .post(`${ip}/device/params/update`, params)
    .then(res => res.data);
};

export const getOperateHistory = params =>
  request
    .get(`${ip}/device/disconHistory`, {
      params
    })
    .then(res => res.data);

export const getMonthReport = id => {
  return request
    .get(`${ip}/monthlyReport?companyId=${id}`)
    .then(res => res.data);
};

export const getDeviceParams = id =>
  request.get(`${ip}/device/params?deviceId=${id}`).then(res => res.data);

export const setDeviceParams = data =>
  request.post(`${ip}/device/params`, data).then(res => res.data);

// 热成像监控/参数设置/设备厂商
export const getFirmList = () =>
  request.get(`${ip}/device/manufacturer`).then(res => res.data);

export const postFirm = data =>
  request.post(`${ip}/device/manufacturer`, data).then(res => res.data);

export const putFirm = data =>
  request.put(`${ip}/device/manufacturer`, data).then(res => res.data);
export const deleteFirm = id =>
  request.delete(`${ip}/device/manufacturer/` + id).then(res => res.data);

// 热成像监控/参数设置/通信协议
export const getArguments = () =>
  request.get(`${ip}/device/protocol`).then(res => res.data);
export const postArguments = data =>
  request.post(`${ip}/device/protocol`, data).then(res => res.data);
export const putArguments = data =>
  request.put(`${ip}/device/p rotocol`, data).then(res => res.data);
export const delArguments = id =>
  request.delete(`${ip}/device/protocol/` + id).then(res => res.data);

// 热成像监控/参数设置/设备型号
export const getModel = data =>
  request.get(`${ip}/device/model`, data).then(res => res.data);
export const postModel = data =>
  request.post(`${ip}/device/model`, data).then(res => res.data);
export const putModel = data =>
  request.put(`${ip}/device/model`, data).then(res => res.data);
export const delModel = id =>
  request.delete(`${ip}/device/model/` + id).then(res => res.data);

// 设备管理/硬盘录像机
export const postDisk = data =>
  request.post(`${ip}/thermal-imager`, data).then(res => res.data);
export const getDisk = data =>
  request.get(`${ip}/thermal-imager`, data).then(res => res.data);
export const delDisk = id =>
  request.delete(`${ip}/thermal-imager/` + id).then(res => res.data);
export const putDisk = data =>
  request.put(`${ip}/thermal-imager`, data).then(res => res.data);

export const postVideoParams = data =>
  request.post(`${ip}/thermal-imager/setCollect`, data).then(res => res.data);
export const getVideoParams = params =>
  request
    .get(`${ip}/thermal-imager/detail`, {
      params
    })
    .then(res => res.data);

export const postVideoAlarm = data =>
  request.post(`${ip}/thermal-imager/setErrorTemp`, data).then(res => res.data);

export const getVideoErrorData = params =>
  request
    .get(`${ip}/thermal-imager/error-data`, {
      params
    })
    .then(res => res.data);

export const getTempData = params =>
  request
    .get(`${ip}/thermal-imager/temp-data`, {
      params
    })
    .then(res => res.data);

export const getSearchCompany = params =>
  request
    .get(`${ip}/company/search`, {
      params
    })
    .then(res => res.data);

export const getTestTemPointList = params =>
  request
    .get(`${ip}/thermal-imager/getMonitorLocation`, {
      params
    })
    .then(res => res.data);

export const getVideoDeviceOverview = params =>
  request
    .get(`${ip}/thermal-imager/index`, {
      params
    })
    .then(res => res.data);

// 获取开启温湿度功能的企业列表
export const getCompanyListOnOd = params =>
  request
    .get(`${ip}/od/companies`, {
      params
    })
    .then(res => res.data);

// 温湿度设备类型(新增)
export const postOdt = params =>
  request.post(`${ip}/odt`, params).then(res => res.data);

// 温湿度设备类型(获取列表)
export const getOdt = params =>
  request
    .get(`${ip}/odt`, {
      params
    })
    .then(res => res.data);

// 温湿度设备类型(删除)
export const delOdt = id =>
  request.delete(`${ip}/odt/${id}`).then(res => res.data);

// 温湿度设备类型(修改)
export const putOdt = params =>
  request.put(`${ip}/odt`, params).then(res => res.data);

// 温湿度设备(删除)
export const delOd = id =>
  request.delete(`${ip}/od/${id}`).then(res => res.data);

// 温湿度设备(新增)
export const postOd = params =>
  request.post(`${ip}/od`, params).then(res => res.data);

// 温湿度设备(编辑)
export const putOdInfo = params =>
  request.put(`${ip}/od`, params).then(res => res.data);

// 温湿度设备(获取)
export const getOd = params =>
  request
    .get(`${ip}/od`, {
      params
    })
    .then(res => res.data);

// 温湿度设备报警事件
export const getOdErrorLists = params =>
  request
    .get(`${ip}/od/error`, {
      params
    })
    .then(res => res.data);

// 用户系统 -> 温湿度 设备总览
export const getOdIndex = params =>
  request
    .get(`${ip}/od/index`, {
      params
    })
    .then(res => res.data);

export const getOdDetail = params =>
  request
    .get(`${ip}/od/detail`, {
      params
    })
    .then(res => res.data);

export const getOdDate = params =>
  request
    .get(`${ip}/od/data`, {
      params
    })
    .then(res => res.data);

// 温湿度设备(报警设置)
export const putOdParam = params =>
  request.put(`${ip}/od/param`, params).then(res => res.data);

// 温湿度设备(获取报警设置信息)
export const getOdParam = params =>
  request
    .get(`${ip}/od/param`, {
      params
    })
    .then(res => res.data);

// 获取热成像支持的城市
export const getVideoCitys = () =>
  request.get(`${ip}/video/city`).then(res => res.data);

export const getVideoCity = cityId =>
  request.get(`${ip}/video/data?areaId=${cityId}`).then(res => res.data);

// 行业管理
export const postTrade = params =>
  request.post(`${ip}/business`, params).then(res => res.data);

export const putTrade = params =>
  request.put(`${ip}/business`, params).then(res => res.data);

export const deleteTrade = id =>
  request.delete(`${ip}/business/${id}`).then(res => res.data);

export const getTrade = () =>
  request.get(`${ip}/business`).then(res => res.data);

// 通过地域类型获取省级列表
export const getRegionByParams = params =>
  request
    .get(`${ip}/province/getProvince`, {
      params
    })
    .then(res => res.data);

// 获取所有地域
export const getRegionAll = params =>
  request.get(`${ip}/city/all`, { params }).then(res => res.data);

// 新增二级地域
export const postSecondArea = params =>
  request.post(`${ip}/city`, params).then(res => res.data);

// 删除二级地域
export const deleteSecondArea = id =>
  request.delete(`${ip}/city/${id}`).then(res => res.data);

// 新增一级地域
export const postRegion = params =>
  request.post(`${ip}/province`, params).then(res => res.data);

// 修改一级地域
export const putRegion = params =>
  request.put(`${ip}/province`, params).then(res => res.data);

// 删除一级地域
export const deleteRegion = id =>
  request.delete(`${ip}/province/${id}`).then(res => res.data);

// 采集方式/网关类型
export const postGatewayType = params =>
  request.post(`${ip}/gateway/type`, params).then(res => res.data);

export const delGatewayType = id =>
  request.delete(`${ip}/gateway/type/${id}`).then(res => res.data);

export const getGatewayType = () =>
  request.get(`${ip}/gateway/type`).then(res => res.data);

// 采集方式/网关列表
export const postGatewayList = params =>
  request.post(`${ip}/gateway/device`, params).then(res => res.data);
export const putGatewayList = params =>
  request.put(`${ip}/gateway/device`, params).then(res => res.data);
export const delGatewayList = id =>
  request.delete(`${ip}/gateway/device/${id}`).then(res => res.data);
export const getGatewayList = params =>
  request.get(`${ip}/gateway/device`, params).then(res => res.data);

/* 设置/设备类型*/
// 设备类别
export const getDeviceTypeSeries = params =>
  request.get(`${ip}/deviceType/series`, { params }).then(res => res.data);

// 设备类型列表
export const getDeviceType = params =>
  request.get(`${ip}/deviceType`, { params }).then(res => res.data);

// 新增设备类型
export const postDeviceType = params =>
  request.post(`${ip}/deviceType`, params).then(res => res.data);

// 删除设备类型
export const deleteDeviceType = id =>
  request.delete(`${ip}/deviceType/${id}`).then(res => res.data);

// 用户
export const getUserAll = params =>
  request
    .get(`${ip}/user/all`, {
      params
    })
    .then(res => res.data);

// 代理账号操作，新增代理企业
export const postUserAgent = params =>
  request.post(`${ip}/user/agent`, params).then(res => res.data);

export const putUserAgent = params =>
  request.put(`${ip}/user/agent`, params).then(res => res.data);

// 编辑用户获取用信息
export const getUserInformation = params =>
  request
    .get(`${ip}/user/byUid`, {
      params
    })
    .then(res => res.data);

export const getSingleCompanyInformation = id =>
  request.get(`${ip}/company/${id}`).then(res => res.data);

export const getGeoJson = param =>
  request.get(`${ip}/req/geo?param=${param}`).then(res => res.data);

// 获取设备级别，父设备列表

export const getParentDeviceList = params =>
  request
    .get(`${ip}/device/byLevel`, {
      params
    })
    .then(res => res.data);
// GET /device/byLevel   参数：companyId(企业ID)、level(设备级别，1-变压器，2-二级表，3-三级表，4-四级表)

/**
 *
 * 三级表查找父设备：调用 GET /device/byLevel  两次，
 * 第一次查二级：level=3,parentId(当前设备的deviceParent值)
 * 第二次查一级：level=2,parentId(二级设备的deviceParent值)   ，其中companyId默认必传
 */

export const getNxEc = params =>
  request.get(`${ip}/nx/ec`, { params }).then(res => res.data);

export const getNxUpload = params =>
  request.post(`${ip}/nx/upload`, params).then(res => res.data);

// export const getNxUploadx = params=> request.post(`${ip}/nx/uploadx`,params).then(res=>res.data)

export const getNxUploadGroup = params =>
  request.post(`${ip}/nx/uploadGroup`, params).then(res => res.data);

export const getNxDownload = companyId =>
  `${ip}/nx/download?companyId=${companyId}`;

export const postMonthlyUpload = params =>
  request.post(`${ip}/monthlyReport/upload`, params).then(res => res.data);

export const postMonthlyReportDownload = companyId =>
  `${ip}/monthlyReport/download?companyId=${companyId}`;

export const getVideoIndex = () =>
  request.get(`${ip}/video/index`).then(res => res.data);

export const get117Detail = params =>
  request
    .get(`${ip}/report/detail-117`, {
      params
    })
    .then(res => res.data);

export const getNxDayPower = params =>
  request.get(`${ip}/nx/day-power`, { params }).then(res => res.data);

export const getNxLoadInfo = params =>
  request.get(`${ip}/nx/api/load_info`, { params }).then(res => res.data);

// 实时负荷
export const getNxOnTimeFuHe = params =>
  request.get(`${ip}/nx/realTimeFuhe`, { params }).then(res => res.data);

export const geNxtPowerData = params =>
  request.get(`${ip}/nx/api/power_index`, { params }).then(res => res.data);

export const getRealPowerData = params =>
  request.get(`${ip}/nx/realPowerData`, { params }).then(res => res.data);

export const getNxRealData = params => {
  const _params = { ...params };
  delete _params.flag;
  return request
    .get(`${ip}/nx/realData/${params.flag}`, { params: _params })
    .then(res => res.data);
};

export const getIdByDeviceNo = params =>
  request
    .get(`${ip}/device/findIdByDeviceNo`, { params })
    .then(res => res.data);

export const getNxCurrentDetail = params =>
  request.get(`${ip}/nx/electricDetail`, { params }).then(res => res.data);
export const getNxPowerDetail = params =>
  request.get(`${ip}/nx/powerDetail`, { params }).then(res => res.data);

export const getNxVoltageDetail = params =>
  request.get(`${ip}/nx/voltageDetail`, { params }).then(res => res.data);

// 能效分析导出接口

// export const exportNxDayPower = params =>
//   request.get(`${ip}/nx/day-power/download`, { params }).then(res => res.data)

export const exportNxDayPower = params =>
  `${ip}/nx/day-power/download${utils.putParamsInUrl(params)}`;

// /nx/realPowerData
export const exportNxDayLoad = params =>
  `${ip}/nx/realTimeFuhe/download${utils.putParamsInUrl(params)}`;

// 日月周电量下载
export const powerDownload = params =>
  `${ip}/nx/realPowerData/download${utils.putParamsInUrl(params)}`;

/**电压、电流、功率因数 */
export const exportNx = params => {
  const flag = params["flag"];
  delete params["flag"];
  return `${ip}/nx/realData/${flag}/download${utils.putParamsInUrl(params)}`;
};

export const exportNxMonthPower = params =>
  `${ip}/nx/month-power/download${utils.putParamsInUrl(params)}`;

/**
 *
 * iot 模块
 */
export const getIotProductList = params =>
  request.get(`${ip}/iot/product/list`, { params }).then(res => res.data);

export const getIotDeviceList = params =>
  request.get(`${ip}/iot/device/list`, { params }).then(res => res.data);

export const getIotDeviceInfo = id =>
  request.get(`${ip}/iot/device/${id}`).then(res => res.data);

/**
 * 禁用设备
 */
export const disableIotDevice = id =>
  request.put(`${ip}/iot/device/${id}`).then(res => res.data);

export const getIotCompanyList = () =>
  request.get(`${ip}/iot/company/findAll`).then(res => res.data);

export const getIotDeviceParmList = params =>
  request.get(`${ip}/iot/device/paramList`, { params }).then(res => res.data);

export const updateIotDevicePram = params =>
  request.get(`${ip}/iot/device/updateParam`, { params }).then(res => res.data);

export const getChildDeviceList = params =>
  request.get(`${ip}/iot/device/childList`, { params }).then(res => res.data);

export const getIotGateWayList = params =>
  request
    .get(`${ip}/iot/device/gatewayListByPK`, { params })
    .then(res => res.data);

export const saveIotDevice = params =>
  request.post(`${ip}/iot/device/save`, params).then(res => res.data);

export const getIotGroupList = params =>
  request.get(`${ip}/iot/group/findList`, { params }).then(res => res.data);

export const deleteIotDevice = id =>
  request.delete(`${ip}/iot/device/${id}`).then(res => res.data);

export const iotDeviceAlertData = params =>
  request
    .get(`${ip}/iot/exceptions/exceptionsList`, { params })
    .then(res => res.data);

export const iotDeviceHistoryData = params =>
  request.get(`${ip}/iot/device/datas`, { params }).then(res => res.data);

export const getIotDdeviceListByCompany = params =>
  request
    .get(`${ip}/iot/device/findByCompany`, { params })
    .then(res => res.data);

export const uploadImagePeiDian = params => {
  return request({
    url: `${ip}/distributionChart/upload`,
    method: "post",
    data: params,
    headers: {
      "Content-Type": "multipart/form-data"
    }
  }).then(res => res.data);
};

// 配电图打点设备列表
export const getGalleryDevice = params =>
  request({
    url: `${ip}/distributionChart/findPreDotDevice`,
    method: "get",
    params
  }).then(res => res.data);

// 配电图列表

export const getGalleryList = params =>
  request({
    url: `${ip}/distributionChart/list`,
    method: "get",
    params
  }).then(res => res.data);

export const addPoint = params =>
  request({
    url: `${ip}/distributionChart/dot`,
    method: "get",
    params
  }).then(res => res.data);

export const removePoint = params =>
  request({
    url: `${ip}/distributionChart/removeDs`,
    method: "delete",
    params
  }).then(res => res.data);

// yun3 预览图片
export const genGalleryUrl = id => `http://img.bjsdzk.com/${id}`;

// 大众预览图片
export const yulanImage = id => `${ip}/distributionChart/review?id=${id}`;

export const removeImage = params =>
  request({
    url: `${ip}/distributionChart/remove`,
    method: "delete",
    params
  }).then(res => res.data);

/**
 * 新首页接口
 *  */

// 实时功率 TOP3
export const getIndexTop3 = params =>
  request({
    url: `${ip}/index/v2/realTimePower`,
    method: "get",
    params
  }).then(res => res.data);

// 用电分析
export const getIndexElectricity = params =>
  request({
    url: `${ip}/index/v2/electricity`,
    method: "get",
    params
  }).then(res => res.data);

// 能耗统计
export const getIndexEnergyConsumption = params =>
  request({
    url: `${ip}/index/v2/energyConsumption`,
    method: "get",
    params
  }).then(res => res.data);

// 安全评估
export const getSafeEvaluation = params =>
  request({
    url: `${ip}/index/v2/safeEvaluation`,
    method: "get",
    params
  }).then(res => res.data);

// 隐患分析
export const getHiddenDanger = params =>
  request({
    url: `${ip}/index/v2/hiddenDanger`,
    method: "get",
    params
  }).then(res => res.data);

// 近期异常事件
export const getRecentException = params =>
  request({
    url: `${ip}/index/v2/recentExceptions`,
    method: "get",
    params
  }).then(res => res.data);

// 配电图部分
export const getIndexGallery = params =>
  request({
    url: `${ip}/index/v2/distributionChart`,
    method: "get",
    params
  }).then(res => res.data);
export const getIndexNavigator = params =>
  request({
    url: `${ip}/index/v2/navigation`,
    method: "get",
    params
  }).then(res => res.data);

// 新建企业渠道
export const addCompanyChannel = data =>
  request({
    url: `${ip}/companyChannel/add`,
    method: "post",
    data
  }).then(res => res.data);

// 查询企业渠道
export const getCompanyChannel = params =>
  request({
    url: `${ip}/companyChannel/list`,
    method: "get",
    params
  }).then(res => res.data);

// 删除企业渠道
export const deleteCompanyChannel = id =>
  request({
    url: `${ip}/companyChannel/delete`,
    method: "delete",
    params: { id }
  }).then(res => res.data);

export const getDeviceInXiTongGaiKuang = params =>
  request({
    url: `${ip}/distributionChart/getDeviceInfo`,
    method: "get",
    params
  }).then(res => res.data);

export const downloadFullPdf = (companyId, token) =>
  `${dazhongIp_windows}/report/downLoadWeekPdf?companyId=${companyId}&token=${token}`;
// request({
//   url: `${ip}/report/downLoadWeekPdf`,
//   method: 'get',
//   params
// }).then(res => res.data)

export const downloadFullPdfMonth = (companyId, token) =>
  `${dazhongIp_windows}/report/downLoadMonthPdf?companyId=${companyId}&token=${token}`;

export const downloadReportPower = (companyId, token) =>
  `${ip}/report/power/download?companyId=${companyId}&token=${token}`;

export const getCommandStatus = params =>
  request({
    url: `${ip}/command/findStatus`,
    method: "get",
    params
  }).then(res => res.data);

export const processStopOrStart = params =>
  request({
    url: `${ip}/command/controlRelaySwitch`,
    method: "get",
    params
  }).then(res => res.data);
